package com.fesco.mis.fm.service.impl;

import com.fesco.mis.fm.dao.BaseDictMapper;
import com.fesco.mis.fm.exception.ExceptionEnum;
import com.fesco.mis.fm.exception.ServiceException;
import com.fesco.mis.fm.model.BaseDict;
import com.fesco.mis.fm.service.BaseDictService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <descption></descption>
 * @date ：2017/9/1 17:50
 * @author：梅海波<meihaibo13186@sinosoft.com.cn>
 * @version:0.1
 */
@Service
public class BaseDictServiceImpl implements BaseDictService{


    @Autowired
    private BaseDictMapper baseDictMapper;


    /**
     * <descption></descption>
     *
     * @param dictId
     * @date ：2017/9/2 16:30
     * @author：梅海波<meihaibo13186@sinosoft.com.cn>
     * @version:0.1
     */
    @Override
    public BaseDict selectByPrimaryKey(Long dictId)throws ServiceException {
        return baseDictMapper.selectByPrimaryKey(dictId);
    }

    /**
     * <descption></descption>
     * @date ：2017/9/4 11:55
     * @author：梅海波<meihaibo13186@sinosoft.com.cn>
     * @version:0.1
     */
    @Override
    public PageInfo getDictList(BaseDict baseDict) {

        if(baseDict.getDictId().longValue() == 100){
            throw new ServiceException(ExceptionEnum.SERVICE_DEMO);
        }
        PageHelper.startPage(baseDict.getPageIndex(), baseDict.getPageSize());
        //return baseDictMapper.selectByPrimaryKey(baseDict.getDictId());
        List<BaseDict> list = baseDictMapper.getBaseDictList(baseDict);
        PageInfo page = new PageInfo(list);
        return page;

    }
}
